package com.aisino.springai.demos.chat.service.function;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Description;

import java.util.function.Function;

@Configuration
public class FunctionTools {
    private static final Logger logger = LoggerFactory.getLogger(FunctionTools.class);

    // 定义请求参数结构
    public record AddRequest(int num1, int num2) {}
    public record MultiplyRequest(int num1, int num2) {}

    @Bean
    @Description("执行加法运算")  // 函数描述（AI模型据此理解功能）
    public Function<AddRequest, Integer> addFunction() {
        return request -> {
            logger.info("调用加法函数：{} + {}", request.num1(), request.num2());
            return request.num1() + request.num2();
        };
    }

    @Bean
    @Description("执行乘法运算")
    public Function<MultiplyRequest, Integer> multiplyFunction() {
        return request -> {
            logger.info("调用乘法函数：{} × {}", request.num1(), request.num2());
            return request.num1() * request.num2();
        };
    }
}